All Questions
Tagged with algorithmtime-limit-exceeded
251 questions
5votes
4answers
477views
Count number of substrings in less time
Given an input string contains letters from 'a' to 'g' Count how many substrings are there in the input string such that frequency of any character inside the substring is not more than the number of ...
13votes
5answers
2kviews
solve n*m matrix processing in less time
I want to solve a problem in less time complexity. Here are the details: Given an n*m matrix, n rows and m columns. Initially, the matrix is empty filled with 0s. ...
8votes
3answers
2kviews
Is set of integers closed under the operation of subtraction?
I was working on a problem, but my solution did not pass the time limit test. Problem Let's say a set of integers is closed under the operation of subtraction if for two distinct elements of this set ...
2votes
1answer
73views
Clique Connect: minimum spanning tree
Problem Statement You are given a weighted undirected graph G with N vertices, numbered 1 to N. Initially, G has no edges. You will perform M operations to add edges to G. The i-th operation (1≤i≤M) ...
6votes
1answer
347views
Codeforces: D2. Counting Is Fun (Hard Version)
The code works okay for the following problem. Problem An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
4votes
2answers
513views
Leetcode: Steps to Make Array Non-decreasing
I was trying out leetcode's Steps to Make Array Non-decreasing As per the challenge's description: You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i ...
1vote
3answers
118views
Find min sum for indices to match equation
I want to reduce time complexity of my code: I have an array of integers arr say [1, 2, 3, 6, 67] I have an equation : a*x+b*y=z, I can use the array values in this ...
9votes
4answers
2kviews
Leetcode : First Missing Positive
I was trying out leetcode's first missing positive. As per the challenge's description: Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an ...
2votes
1answer
98views
HackerRank Algorithm Problem: Climbing the Leaderboard (Python)
Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
2votes
1answer
763views
Traveling Salesman Problem for visiting cities
Implement TSP problem using best first algorithm (so it will be backtracking, branch-and-bound, and best-first). Since you are looking for a cycle, the start/finish city is not important. Therefore we ...
2votes
1answer
140views
Find character at given index in a sorted sub strings [closed]
For a given string say dbac the possible substrings are [d,db,dba,dbac,b,ba,bac,a,ac,c]. Sort them and concatenate to a string: ...
4votes
2answers
596views
O(nlogn) Lexicographically minimal rotation code but tle on this particular case
Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
10votes
3answers
2kviews
Repeatedly remove a substring quickly
I'm trying to solve the USACO problem Censoring (Bronze), which was the first problem for the 2015 February contest. My solution works for some test cases, but then times out for test cases 7-15. I ...
2votes
2answers
98views
For two sequences N and M, display counts of elements n from N below each m from M up to the first n above m
A school's task: There are two sequences n_tab and m_tab. For every element m in m_tab ...
7votes
2answers
1kviews
Find all combinations of length 3 whose sum is divisible by a given number
I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size. The problem: Given a list ...